/**
 * 表格列表的业务逻辑
 */

import { onMounted, reactive, ref, nextTick } from "vue"
import { DeptListResult, ListParam } from '@/api/dept/DeptModel'
import { getDeptListApi } from '@/api/dept/dept'

export default function userDeptTable() {
    // 定义表格的高度
    const tableHeight = ref(0)

    // 定义列表查询参数
    const searchParams = reactive<ListParam>({
        searchName: ''
    })
    // 定义表格的数据
    const tableData = reactive<DeptListResult>({
        list: []
    })
    // 获取表格的数据
    const getDeptList = async () => {
        let res = await getDeptListApi(searchParams)
        if(res && res.code === 200) {
            // console.log('加载表格数据===', res)
            tableData.list = res.data
        }
    }
    // 首次加载
    onMounted(() => {
        getDeptList()
        nextTick(() => {
            tableHeight.value = window.innerHeight - 200
        })
    })
    return {
        tableHeight,
        searchParams,
        tableData,
        getDeptList
    }
}